import lombok.extern.slf4j.Slf4j;
import net.xdclass.AccountApplication;
import net.xdclass.component.SmsComponent;
import net.xdclass.mapper.TrafficMapper;
import net.xdclass.model.TrafficDO;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;

import java.io.UnsupportedEncodingException;
import java.util.Random;

/**
 * @Description
 * @Author lihw
 * @Date 2023/4/14 23:11
 */
@SpringBootTest(classes = AccountApplication.class)
@Slf4j
public class AccountTestApplication {

    @Autowired
    SmsComponent smsComponent;

    @Autowired
    RedisTemplate redisTemplate;

    @Autowired
    private TrafficMapper trafficMapper;


    @Test
    void contextLoads() {
        shardingsphereTest();
    }

    /**
     * 短信发送测试
     */
    public void sendSmsTest() throws UnsupportedEncodingException {
        smsComponent.send("17862806857", "CST_hecci10120", "8976");
    }

    public void redisTest() {
        redisTemplate.opsForValue().set("test_time", "ddd");
    }

    public void shardingsphereTest() {
        Random random = new Random();
        for(int i=0;i<3;i++) {
            TrafficDO trafficDO = new TrafficDO();

            trafficDO.setAccountNo(Long.valueOf(random.nextInt(1000)));
            trafficMapper.insert(trafficDO);
        }
    }
}
